let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let path = require('path');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');   //todo 自动打开浏览器插件
const domainPath = require('../conf/dev.config');


process.noDeprecation = true;

module.exports = {
    entry: {
        app: [path.join(__dirname, '../src/App.js'), 'webpack-hot-middleware/client'],
        common: ['react', 'react-dom', 'dva']
    },
    devtool: 'source-map',
    output: {
        path: path.join(__dirname, "../dist/"),
        filename: 'js/[name].js',
        chunkFilename: 'js/[name].chunk.js',
        publicPath: '/'
    },
    resolve: {
        // require文件的时候不需要写后缀了，可以自动补全
        extensions: ['.js', '.jsx', '.css', '.scss']
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            exclude: /(node_modules)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    cacheDirectory: true,
                    presets: ['env', 'react'],
                    plugins: [
                        ["import", { libraryName: "antd", style: "css" }],
                        ["transform-runtime"],
                        ["transform-class-properties"],
                        ["transform-async-to-generator"],
                        ["transform-object-rest-spread"]
                    ]
                }
            }]
        },
        { test: /\.css$/, loader: 'style-loader!css-loader' },
        {
            test: /\.less$/,
            use: [{
                loader: 'style-loader' // creates style nodes from JS strings
            }, {
                loader: 'css-loader' // translates CSS into CommonJS
            }, {
                loader: 'less-loader', options: { javascriptEnabled: true } // compiles Less to CSS
            }]
        },
        {
            test: /\.((ttf|eot|woff|svg)(\?t=[0-9]\.[0-9]\.[0-9]))|(ttf|eot|woff|svg)\??.*$/,
            loader: 'url-loader',
            options: {
                limit: 10000,
                name: 'iconfont/[name].[ext]'
            }
        },
        {
            test: /\.(png|jpg|gif)$/,
            loader: 'url-loader',
            options: {
                limit: 10000,
                name: 'images/[name].[ext]'
            }
        }]
    },
    plugins: [
        new OpenBrowserPlugin({ url: domainPath.cdnPath }), //todo kim-stamp 创建一个自动打开浏览器插件
        new webpack.optimize.CommonsChunkPlugin({
            filename: "js/common.js",
            name: "common"
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new HtmlWebpackPlugin({
            filename: '../views/index.ejs',
            hash: true,
            template: 'src/views/index.ejs',
            favicon: './favicon.ico' //注意部署租户公司把这行注释掉，或者换成租户公司的logo
        })
    ]
};